package com.kedi.usercenter.utils;

import com.kedi.usercenter.vo.ResultVo;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.List;
import java.util.Map;

public class LoginCommonUtil {


    /**
     * 该方法是提取登录方法的公共代码， 无特殊意义
     * @author Zyred
     * @param res
     * @return
     */
    public static ResultVo commonLogin(Map res, List<String> urls, StringRedisTemplate redisTemplate) throws Exception {
        //创建Token生成策略，生成token
        //cation参数选项： 老人APP as    老人PC bs  社区APP cs  社区PC ds
        TokenGenerationStrategy strategy = new TokenGenerationStrategy(res, "as", urls);
        String token = strategy.getToken();
        //存入redis中
        LoginSaveTokenToRedisUtil redisUtil = new LoginSaveTokenToRedisUtil(
                token, strategy.getValue(), redisTemplate);
        redisUtil.saveTokenToRedis();
        res.put("token", token);
        return ResultVoUtil.success(res);
    }

}
